# How to convert website into kotlin android app in android studio

Webview Kotlin Webview Kotlin

WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your application using WebView. WebView makes turns your application to a web application

# Complete Code

Download

# UI Design

(adsbygoogle = window.adsbygoogle || []).push({});
  1. Include WebView in the Main XMl file:

In activity_main.xml

    <WebView
                android:id="@+id/webView"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

1
2
3
4
5
6
7
8
9
10
11
12
13

# Add necessary permission for Internet

AndroidManifest.xml

 <uses-permission android:name="android.permission.INTERNET" />
1

# Update Main Activity


webView = findViewById(R.id.webView) as WebView
webView.settings.javaScriptEnabled = true
webView.settings.setAppCacheEnabled(true)
webView.loadUrl("https://google.com/")
webView.webViewClient = object : WebViewClient() {

            override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {

                webView.loadUrl("file:///android_asset/error.html")
            }

1
2
3
4
5
6
7
8
9
10
11
12